<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../base_top.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>地址列表</title>
    <%@ include file="../base_head.jsp" %>
	
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/user/style.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/user/common.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/user/address_style.css">
	<script type="text/javascript" src="<%=basePath%>js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>layer/layer.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    	function checkCount() {
    		var n = $("#add_num").val();
    		if (n >= 20) {
    			return false;
    		}
    		return true;
    	}
    	$(".btn").click(function() {
    		if(checkCount()) {
    			layer.open({
    	 	    	type: 2,
    	 	    	offset: '100px',
    	 	    	title: '添加地址',
    	 	    	shadeClose: true,
    	 	    	shade: 0.8,
    	 	    	area: ['60%', '80%'],
    	 	    	content: 'user/address/addressAdd.jsp' //iframe的url
    	 	    }); 
    		} else {
    			layer.alert('地址库数量已达上限', 
	    			{
	   				  skin: 'layui-layer-lan'
	   				  ,closeBtn: 0
	   				  ,offset:'100px'
	   				}
   				);
    		}
	   		
    	});
    	
    	$(".del_sub").click(function() {
    		var conf = confirm('确定删除？');
    		var a = $(this);
    		var id = $(this).parent().parent().parent().find("#add_num").val();
    		if(conf) {
    			$.ajax({
    				cache: false,
    				url:"user/addressDelete",
    				type: "GET",
    				data: {id: id},
    				dataType:"json",
    			    success: function(data) {
    			    	a.parent().parent().parent().remove();
    			    }
    			});
    		}
    	});
    	
    	$(".set_default").click(function() {
    		var id = $(this).parent().parent().parent().find("#add_num").val();
    		$.ajax({
				cache: false,
				url:"user/setDefaultAddress",
				type: "GET",
				data: {id: id},
				dataType:"json",
			    success: function(data) {
			    	window.location.reload();
			    }
			});
    	});
    	
    	$(".edit_sub").click(function() {
    		var id = $(this).parent().parent().parent().find("#add_num").val();
    		layer.open({
	 	    	type: 2,
	 	    	offset: '100px',
	 	    	title: '添加地址',
	 	    	shadeClose: true,
	 	    	shade: 0.8,
	 	    	area: ['80%', '80%'],
	 	    	content: 'user/addressUpdate?id=' + id
	 	    });
    	});
    	
    });
    
    </script>
  </head>
  
<body>
<!--topbar开始-->
<%@ include file="../page_topbar.html" %>
<!--topbar结束-->
<div id="wrap">
    <!--search开始-->
    <%@ include file="../selfCenter_search.html" %>
    <!--search结束-->
    <!--左边订单中心开始-->
    <%@ include file="../selfCenter_menu.html" %>
    <!--左边订单中心结束-->
    <!--右边新增收货地址开始-->
    <div class="addre_add">
        <input type="button" value="新增收货地址" class="btn">
        <input type="hidden" value='<s:property value="#request.addNum"/>' id="add_num"/>
        <div class="text">您已创建<s:property value="#request.addNum"/>个收货地址，最多可创建20个</div>
    </div>
    <!--收货地址详细内容开始-->
    <div class="addre_detail">
    	<!--单个收货地址开始-->
    	<s:iterator value="#request.addList" id="add">
    	<div class="addre_detail_single" style="margin-top: 24px;">
            <input type="hidden" id="add_num" value='<s:property value="#request.add.addressNum"/>'/>
            <div class="addre_detail_title">
                <div class="name"><s:property value="#request.add.addressName"/></div>
                <!-- <div class="place">河北</div> -->
                <s:if test="#request.add.ifdefault == 1">
                <div class="default">默认地址</div>
                </s:if>
                <div class="addre_detail_title_close"><a href="JavaScript:void(0);" class="del_sub">X</a> </div>
            </div>
            <div class="addre_detail_leftbar">
                <ul>
                    <li>收货人:</li>
                    <li>所在地区:</li>
                    <li>地址:</li>
                    <li>手机:</li>
                    <li>固定电话:</li>
                    <li>电子邮箱:</li>
                    <li>邮编:</li>
                </ul>
            </div>
            <div class="addre_detail_rightbar">
                <ul>
                    <li><s:property value="#request.add.daName"/></li>
                    <li><s:property value="#request.add.daRegion"/></li>
                    <li><s:property value="#request.add.daAddress"/></li>
                    <li><s:property value="#request.add.daPhonenum"/></li>
                    <li><s:property value="#request.add.daFixphonenum"/></li>
                    <li><s:property value="#request.add.daEmail"/></li>
                    <li><s:property value="#request.add.daPostcode"/></li>
                </ul>
                <s:if test="#request.add.ifdefault == 0">
                <div class="default"><a href="JavaScript:void(0);" class="set_default">设为默认</a> </div>
                </s:if>
                <div class="write"><a href="JavaScript:void(0)" class="edit_sub">编辑</a> </div>
            </div>
        </div>
    	</s:iterator>
        <!--单个收货地址结束-->
        <!--右边新增收货地址开始-->
        <div class="addre_add" style="margin-top: 0px;">
            <input type="button" value="新增收货地址" class="btn">
            <div class="text">您已创建<s:property value="#request.addNum"/>个收货地址，最多可创建20个</div>
        </div>
    </div>
    <!--收货地址详细内容结束-->
    <!--右边新增收货地址结束-->
    <!--广告-->
    <%@ include file="../selfCenter_bottom_four-ad.html" %>
    <!--广告结束-->
</div>
</body>
</html>
